define(function (require, exports, module) {
    var CReader_TextSelectTool = require("./Reader_TextSelectTool.js");

    /**
     * @description Name of text selection tool.
     * @constant
     * @type {String}
     */
    WebPDF.Tools.TOOL_NAME_SELECTTEXT = "Select Text";

    /**
     * @description Tool handler of text selection.
     * @extends WebPDF.Tools.IReaderToolHandler
     * @constructor
     * @return instance of text selection tool handerl.
     */
    WebPDF.Tools.TextSelectionToolHandler = function (readerApp) {
        var _isLButtonDown = false,
            /**
             * @type {WebPDF.TextSelect.CReader_TextSelectTool}
             * @private
             */
            _textSelectTool = null,
            _readerApp = readerApp;

        /**
         * @description Get text selection tool.
         * @return {WebPDF.TextSelect.CReader_TextSelectTool} text selection tool.
         */
        this.getTextSelectTool = function () {
            return _textSelectTool;
        };

        this.onInit = function () {          
            _textSelectTool = CReader_TextSelectTool.getTextSelectTool(_readerApp, true);
        };

        this.onDestroy = function () {
        };

        this.getName = function () {
            return WebPDF.Tools.TOOL_NAME_SELECTTEXT;
        };

        this.onActivate = function () {
            var mainView = _readerApp.getMainView();
            if (mainView) {
                var docView =mainView.getDocView();
                var jqDocViewContainer = $("#" + docView.getDocViewContainerID());
                jqDocViewContainer.css({ 'cursor': "text" });
            }
        };

        this.onDeactivate = function () {
            _textSelectTool.clearSelection();
        };

        this.isEnabled = function () {
            return true;
        };

        this.isProcessing = function () {
            return _isLButtonDown;
        };

        this.onLButtonDown = function (event) {
            _isLButtonDown = true;
            var docView = _readerApp.getMainView().getDocView();
            var jqDocViewContainer = $("#" + docView.getDocViewContainerID());
            if (!WebPDF.Common.containsNode(jqDocViewContainer.get(0), event.target, true)) {
                return false;
            }
            _textSelectTool.onLButtonDown(event);
            return true;
        };

        this.onLButtonUp = function (event) {
            _isLButtonDown = false;
            _textSelectTool.onLButtonUp(event);
            return true;
        };

        this.onLButtonDblClk = function (event) {
            var docView = _readerApp.getMainView().getDocView();
            var jqDocViewContainer = $("#" + docView.getDocViewContainerID());
            if (!WebPDF.Common.containsNode(jqDocViewContainer.get(0), event.target, true)) {
                return false;
            }
            _textSelectTool.onLButtonDblClk(event);
            return true;
        };

        this.onMouseMove = function (event) {
            _textSelectTool.onMouseMove(event);
            return true;
        };

        this.onRButtonDown = function (event) {
            return false;
        };

        this.onRButtonUp = function (event) {
            return false;
        };

        this.onRButtonDblClk = function (event) {
            return false;
        };

        this.onMouseWheel = function (event) {
            return false;
        };

        this.onMouseOver = function (event) {
            return false;
        };

        this.onMouseOut = function (event) {
            return false;
        };

        this.onMouseEnter = function (event) {
            return false;
        };

        this.onMouseLeave = function (event) {
            _textSelectTool.onLButtonUp(event);
            return false;
        };

        this.onDoubleTap = function(event) {
            return false;
        };
        this.onPinchIn = function(event) {
            return false;
        };
        this.onPinchOut = function(event) {
            return false;
        };
        this.onHold = function(event) {
            var docView = _readerApp.getMainView().getDocView();
            var jqDocViewContainer = $("#" + docView.getDocViewContainerID());
            if (!WebPDF.Common.containsNode(jqDocViewContainer.get(0), event.target, true)) {
                return false;
            }
            var touch = event.gesture ? event.gesture.touches[0] : null;
            _textSelectTool.onLButtonDblClk(touch);
            return true;
        };
    };

    return WebPDF.Tools.TextSelectionToolHandler;
});